<?php

namespace app\controller\api;

use app\exception\ErrnoPlus;
use app\service\SendNoticeTableService;
use share\controller\ApiBaseController;
use share\exception\ApiException;
use share\service\ContextService;

class SendNoticeTableController extends ApiBaseController
{
    public function all_action()
    {
        $clientType = ContextService::getClientType();
        if ($clientType === 'IOS') {
            return self::fail("no data for IOS", ErrnoPlus::NOT_BACK_DATA);
        }
        $language = $this->request->param("language");
        if (!$language) {
            throw new ApiException("params language is empty", ErrnoPlus::COMMON_ERROR);
        }
        $res = SendNoticeTableService::getAllNotice($language);
        if(empty($res)){
            return self::fail("no data", ErrnoPlus::NOT_BACK_DATA);
        }
        return self::ok($res);
    }

    public function all_v2_action()
    {
        $language = $this->request->param("language");
        if (!$language) {
            $language = 'CN';
        }
        $res = SendNoticeTableService::getAllNoticeByLanguage($language);
        if(empty($res)){
            return self::fail("no data", ErrnoPlus::NOT_BACK_DATA);
        }
        return self::ok($res);
    }
}
